#!/bin/bash

JAVAC="`which javac`"

if [ ! -x "$JAVAC" ]; then
	echo "Couldn't find Java Compiler..."
	exit 1
fi
$JAVAC -cp mysql-connector-java-5.0.4-bin.jar:junit-4.1.jar server/*.java
if [ ! $? == "0" ]; then
	echo "Error compiling server source code... please fix the errors"
	exit 1
fi
echo "Main-Class: server.Server" > Server.meta
jar cmf Server.meta server.jar server mysql-connector-java-5.0.4-bin.jar
if [ ! $? == "0" ]; then
	rm server/*.class
	echo "Error creating server JAR file... please fix the errors"
	exit 1
fi
rm Server.meta
rm server/*.class
echo "Done, server.jar created OK."
